<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>index</title>
</head>
<body>
<%
    String url = "jdbc:mysql://localhost:3306/books";
    String user = "root";
    String pwd = "";
    String sql = null;
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn=DriverManager.getConnection(url,user,pwd);
    sql = "update visitcnt set cnt = cnt+1";
    if(session.isNew())
        conn.createStatement().execute(sql);
    sql = "select cnt from visitcnt";
    ResultSet ans = conn.prepareStatement(sql).executeQuery();
    ans.next();
    application.setAttribute("cnt", String.valueOf(ans.getInt("cnt")));
    out.print("你是第"+application.getAttribute("cnt")+"个访问此网站的人");
%>
    <%=request.getRemoteAddr()%>
</body>
</html>
